package com.huike.web.controller.report;

import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.common.core.domain.AjaxResult;
import com.huike.report.domain.vo.IndexBaseInfoVO;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import com.huike.report.result.ReportIndexStatisticsData;
import com.huike.report.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description 首页报表相关接口
 * @Date 2023-10-10
 */
@RestController
@RequestMapping("/index")
@Slf4j
@Api(tags = "首页报表相关接口")
public class IndexController {
    @Autowired
    private ReportService reportService;

    /**
     * 基础数据统计接口
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    @ApiOperation("基础数据统计接口")
    public AjaxResult<IndexBaseInfoVO> getBaseInfo(String beginCreateTime,String endCreateTime){
        IndexBaseInfoVO vo = reportService.getBaseInfo(beginCreateTime,endCreateTime);
        return AjaxResult.success(vo);
    }

    /**
     * 获取今日简报数据
     * @return
     */
    @GetMapping("/getTodayInfo")
    @ApiOperation("获取今日简报数据")
    public AjaxResult<IndexTodayInfoVO> getTodayInfo(){
        IndexTodayInfoVO vo = reportService.getTodayInfo(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        return AjaxResult.success(vo);
    }

    /**
     * 获取待办数据
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getTodoInfo")
    @ApiOperation("获取待办数据")
    public AjaxResult<IndexTodoInfoVO> getTodoInfo(String beginCreateTime,String endCreateTime){
        IndexTodoInfoVO vo = reportService.getTodoInfo(beginCreateTime,endCreateTime);
        return AjaxResult.success(vo);
    }

    /**
     * 线索转化成龙虎榜
     * @param indexStatisticsVo
     * @return
     */
    @GetMapping("/salesStatistic")
    @ApiOperation("线索转化成龙虎榜")
    public AjaxResult<List<ReportIndexStatisticsData>> salesStatistic(IndexStatisticsVo indexStatisticsVo){
        //最小时分秒
        indexStatisticsVo.setBeginCreateTime(indexStatisticsVo.getBeginCreateTime() + " 00:00:00");
        //最大时分秒
        indexStatisticsVo.setEndCreateTime(indexStatisticsVo.getEndCreateTime() + " 23:59:59");
        List<Map<String,Object>> list = reportService.salesStatistic(indexStatisticsVo);
        return AjaxResult.success(list);
    }

    /**
     * 商机转换龙虎榜
     * @param request
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    @ApiOperation("商机转换龙虎榜")
    public AjaxResult<List<ReportIndexStatisticsData>> businessChangeStatistics(IndexStatisticsVo request){
        //最小时分秒
        request.setBeginCreateTime(request.getBeginCreateTime() + " 00:00:00");
        //最大时分秒
        request.setEndCreateTime(request.getEndCreateTime() + " 23:59:59");
        List<Map<String,Object>> list = reportService.businessChangeStatistics(request);
        return AjaxResult.success(list);
    }
}
